# -*- coding: utf-8 -*- 
# @Time : 2022/3/29 20:38 
# @Author : johnforrest 
# @File : getdirectory.py

import os
# 当前目录
print(os.getcwd())
# 自动连接路径
print(os.path.join('myproject',"AI"))
# 自动连接路径
print(os.path.join('myproject',"AI"))
print("------------------listdir--------------------")
# 列出所有文件
print(os.listdir())
print("------------------basename--------------------")
print(os.path.basename(os.getcwd()))

path = "F:/data/水电流域/2022.09.26预报数据对比/9月预报数据对比/欧洲长期预测成果/导出数据/十个流域求交.xlsx"
filename=os.path.basename(path)
print(os.path.basename(path))
print( "---返回文件名称"+os.path.dirname(path) )
print("---返回文件路径",os.path.dirname(path))

stem, suffix = os.path.splitext(filename)
print(stem) # test
print( suffix) #    .py

print("------------------split路径拼接--------------------")
pd = os.path.split(os.path.abspath(path))[0]
print(pd)

pd1=os.path.split(os.path.abspath(pd))[0]
pd2=os.path.split(os.path.abspath(pd))[1]
print("pd1,pd2"+pd1,pd2)

pd = os.path.split(os.path.abspath(path))[1]
print(pd)
# print(os.listdir('e:\\code'))

